!
! open and read parameter file for autoflat
!
!
!

Subroutine readpar(CFILE,nameflat, saturace, level, MINRANGE, MAXRANGE, nstep)

Character(len=*) :: CFILE, nameflat
Real :: saturace, level, MINRANGE, MAXRANGE
Integer :: nstep
Integer :: i,j
Character(len=255) :: radek

open(21,file=CFILE,status='old',err=670)
do
   read(21,'(A)',end=670,err=670) radek
   i = index(radek,'!')
   if( i == 0 ) i = len_trim(radek)
   j = index(radek,'=') + 1
   !         write(*,*) trim(radek),i,j
   
   if( index(radek(:i),'NAMEFLAT') /= 0 ) read(radek(j:),*) nameflat
 
   if( index(radek(:i),'SATURACE') /= 0 ) read(radek(j:),*) saturace

   if( index(radek(:i),'LEVEL') /= 0 )    read(radek(j:),*) level

   if( index(radek(:i),'MINRANGE') /= 0 ) read(radek(j:),*)  minrange

   if( index(radek(:i),'MAXRANGE') /= 0 ) read(radek(j:),*)  maxrange

   if( index(radek(:i),'NSTEP') /= 0 )    read(radek(j:),*)  nstep
enddo
670 close(21)

!write(*,*) trim(nameflat), saturace, level, MINRANGE, MAXRANGE, nstep

end Subroutine
